//
//  FXCCenterCollectionItem.m
//  Various
//
//  Created by 范新晨 on 16/3/25.
//  Copyright © 2016年 Harword. All rights reserved.
//

#import "FXCCenterCollectionItem.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "UIColor+convert.h"
@interface FXCCenterCollectionItem ()

//大标题
@property (nonatomic, strong) UILabel *titleLabel;
//小标题
@property (nonatomic, strong) UILabel *subTitleLabel;
//图片
@property (nonatomic, strong) UIImageView *centerImgView;
//详情
@property (nonatomic, strong) UILabel *detailLabel;
//作者
@property (nonatomic, strong) UILabel *authorLabel;
//日期
@property (nonatomic, strong) UILabel *dataLabel;
//星期
@property (nonatomic, strong) UILabel *weakLabel;
//返回到第一个
@property (nonatomic, strong) UIButton *backToFirst;

@end

@implementation FXCCenterCollectionItem

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setSubviews];
        self.layer.cornerRadius = 8;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setSubviews{
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
//    self.titleLabel.backgroundColor = [UIColor orangeColor];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    
    self.subTitleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.subTitleLabel];
    self.subTitleLabel.font = [UIFont systemFontOfSize:14];
//    self.subTitleLabel.backgroundColor = [UIColor orangeColor];
    
    self.centerImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.centerImgView];
//    self.centerImgView.backgroundColor = [UIColor orangeColor];
    
    self.detailLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.detailLabel];
//    self.detailLabel.backgroundColor = [UIColor orangeColor];
    self.detailLabel.font = [UIFont systemFontOfSize:14];
    self.detailLabel.textColor = [UIColor grayColor];
    self.detailLabel.numberOfLines = 0;
    
    self.authorLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.authorLabel];
    self.authorLabel.textAlignment = NSTextAlignmentRight;
//    self.authorLabel.backgroundColor = [UIColor orangeColor];
    
    self.dataLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.dataLabel];
    self.dataLabel.font = [UIFont systemFontOfSize:12];
    self.dataLabel.textAlignment = NSTextAlignmentRight;
    
    self.weakLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.weakLabel];
    self.weakLabel.font = [UIFont systemFontOfSize:12];
    
    self.backToFirst = [[UIButton alloc] init];
    [self.contentView addSubview:self.backToFirst];
    [self.backToFirst addTarget:self action:@selector(backToFirstBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.backToFirst setImage:[UIImage imageNamed:@"backtohome_normal"] forState:UIControlStateNormal];
    self.backToFirst.backgroundColor = [UIColor redColor];
    self.backToFirst.layer.cornerRadius = 20;
    
    
}
- (void)backToFirstBtn{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"back" object:nil];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(50);
    }];
    
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(30);
    }];
    
    [self.centerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(self.subTitleLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(200);
    }];
    
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.left.mas_equalTo(15);
        make.top.equalTo(self.centerImgView.mas_bottom).offset(5);
        make.bottom.mas_equalTo(self.authorLabel.mas_top).offset(-5);
    }];

    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(50);
        make.bottom.mas_equalTo(10);
    }];
    
    [self.dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.right.mas_equalTo(-5);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
    }];
    
    [self.backToFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.right.equalTo(self.dataLabel.mas_left).offset(-5);
        make.width.height.mas_equalTo(40);
        
    }];
    
    
}

- (void)setModel:(FXCPianoModel *)model{
    self.titleLabel.text = model.title;
    self.subTitleLabel.text = model.sub_title;
    [self.centerImgView sd_setImageWithURL:[NSURL URLWithString:model.cover_image] placeholderImage:[UIImage imageNamed:@"common_logo_normal"]];
    self.detailLabel.text = model.digest;
    self.authorLabel.text = model.author_username;
    self.dataLabel.text = model.publish_date;
    
    

}



@end
